package com.lyf.scm.common.util.style;

import com.alibaba.excel.metadata.Head;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Workbook;

/**
 * 直营预测计划——目标与销售差异  excel单元格格式处理器
 *
 * @author wangchlei
 * @date 2020/08/26
 */
public class DirectlyDifferinCellWriterHandler extends PercentageCellWriteHandler {
    private final Boolean validGmv;
    public static final int RON_MUN = 9;

    public DirectlyDifferinCellWriterHandler(Boolean validGmv) {
        this.validGmv = validGmv;
    }

    @Override
    protected void initCellStyle(Workbook workbook) {
        super.initCellStyle(workbook);
    }

    @Override
    protected void setContentCellStyle(Cell cell, Head head, Integer relativeRowIndex) {
        if (MAIN_TITLES.contains(head.getHeadNameList().get(0))) {
            cell.setCellStyle(bodyGeneralCellStyleLeft);
        } else {
            if (validGmv) {
                if (cell.getRow().getRowNum() % RON_MUN == 0) {
                    if (cell.getCellTypeEnum().compareTo(CellType.STRING) != 0) {
                        cell.setCellStyle(percentageCellStyle);
                    } else {
                        cell.setCellStyle(bodyGeneralCellStyleRight);
                    }
                } else {
                    cell.setCellStyle(bodyGeneralCellStyleRight);
                }
            } else {
                //这里的标题每列只有一个标题，取第一个即可
                cell.setCellStyle(bodyGeneralCellStyleRight);
            }
        }
    }
}
